<template>
	<view class="page">
	<!-- <view class="page" @touchstart="touchStart" @touchend="touchEnd"> -->

		<view class="uni-textarea">
			<textarea placeholder="这一刻的想法..." v-model="form.content" />
		</view>
		<view class="uni-list list-pd">
			<view class="uni-list-cell cell-pd">
				<view class="uni-uploader">
					<view class="uni-uploader-body">
						<view class="uni-uploader__files">
							<view class="container">
								<view class="example-body">
									<uni-file-picker limit="9" :del-icon="false" title=""
										@select="myselect"></uni-file-picker>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="footer">
			<button type="default" class="feedback-submit" @click="uploadImages">提交</button>
		</view>

	</view>
</template>

<script>
	import image from '@/common/image.js';

	var sourceType = [
		['camera'],
		['album'],
		['camera', 'album']
	]
	var sizeType = [
		['compressed'],
		['original'],
		['compressed', 'original']
	]
	export default {
		data() {
			return {
				form: {
					uid: this.$.getUser("uid"),
					content: "",
					imageList: []
				},

				sourceTypeIndex: 2,
				sourceType: ['拍照', '相册', '拍照或相册'],
				sizeTypeIndex: 2,
				sizeType: ['压缩', '原图', '压缩或原图'],
				countIndex: 8,
				count: [1, 2, 3, 4, 5, 6, 7, 8, 9],

				//侧滑返回start
				startX: 0, //点击屏幕起始位置
				movedX: 0, //横向移动的距离
				endX: 0, //接触屏幕后移开时的位置
				//end
			}
		},
		onUnload() {
			this.form.imageList = [],
				this.sourceTypeIndex = 2,
				this.sourceType = ['拍照', '相册', '拍照或相册'],
				this.sizeTypeIndex = 2,
				this.sizeType = ['压缩', '原图', '压缩或原图'],
				this.countIndex = 8;
		},
		methods: {
			// 选择上传图片
			myselect(file) {
				console.log("上传图片....", file);
				file.tempFilePaths.forEach((tempFile) => {
					uni.uploadFile({
						url: 'http://' + this.$.baseUrl + '/file/uploader',
						name: 'file',
						filePath: file.tempFilePaths[0],
						success: (res) => {
							let imgRes = JSON.parse(res.data).data;
							this.form.imageList.push(imgRes);
						}
					});
				});
			},
			// 发动态
			uploadImages() {
				if (!this.form.content) {
					uni.showModal({
						content: '内容不能为空',
						showCancel: false,
					});
					return;
				}
				uni.showLoading({
					title: '发布中'
				});
				this.$.ajax({
					url: '/post/sharePost',
					type: 'POST',
					data: this.form,
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						uni.showToast({
							icon: 'success',
							title: "发布成功"
						});
						// 返回到朋友圈
						uni.navigateBack({
							delta: 1
						});
					},
					fail: (err) => {
						console.error(err)
					},
				});
			}
		}
	}
</script>

<style lang="scss">
	@import url("../../common/uni.css");


	.footer {
		margin-top: 80upx;
	}

	.uni-uploader__files {
		display: unset;
	}

	.cell-pd {
		padding: 20upx 30upx;
	}

	.example-body {
		padding: 10px;
		padding-top: 0;
	}

	.uni-textarea {
		width: auto;
		padding: 20upx 25upx;
		line-height: 1.6;
		height: 150upx;
	}

	.uni-list::before {
		height: 0;
	}

	.uni-list:after {
		height: 0;
	}

	.list-pd {
		margin-top: 0;
	}

	.close-view {
		text-align: center;
		line-height: 30upx;
		height: 35upx;
		width: 35upx;
		background: #ef5350;
		color: #FFFFFF;
		position: absolute;
		top: 1upx;
		right: 1upx;
		font-size: 35upx;
		border-radius: 8upx;
	}

	.page {
		width: 750upx;
		height: 100%;
	}
</style>